DHTMLX Documentation

Storing additional data


There are three possible approaches to load additional data:

- hidden columns;
- user data;
- attributes.

Hidden columns


It is possible to define a column as hidden - in such case it will not be visible for a user, but it will be accessible by API. So it will be possible to take the data from it.

In case of initialization from js code:
    ...
    grid.init();
    grid.setColumnHidden(index,true);

In case of initialization from XML:
<rows>
    <head>
        <column hidden="true">Dummy</column>
    ...

The data can be accessed as data of any other columns:
    grid.cells(i,j).getValue();
    grid.cells(i,j).setValue(some);

Data of a hidden column is included in the serialization by default, can't be controlled by setSerializableColumns command.
This data is available during dataprocessor calls.

UserData


UserData is a special tag, which can be a child of rows or row tags. In the first case userdata is related to the whole grid, while in the second case it will be related to a specific row.

<?xml version='1.0' encoding='iso-8859-1'?>
    <rows>
        <userdata name="somName1">some data</userdata>
        <row id="unique_rowid">
                <userdata name="someName1"> some row data </userdata>
                <userdata name="someName2"> some row data </userdata>
                <cell>cell content</cell>
                <cell><![CDATA[<font color="red">cell</font> content]]></cell>
        </row>
    </rows>

To access global userdata:
    grid.getUserData("","someName1"); // some data
    grid.setUserData("","someName1","new value");

To access row related userdata:
    grid.getUserData("unique_rowid","someName1"); // some row data
    grid.setUserData("unique_rowid","someName1","new value");

The userdata may be included in the serialization using setSerializationLevel command (is disabled by default).
This data is available during dataprocessor calls.

Attributes ( dhtmlxgrid 1.6+ )


When loading from XML any attribute of row or cell tag can be accessed programmatically.

<?xml version='1.0' encoding='iso-8859-1'?>
    <rows>
        <row id="unique_rowid" some="data">
                <cell some="data">cell content</cell>
        </row>
    </rows>


To access row attributes:
    grid.getRowAttribute("unique_rowid","some");
    grid.setRowAttribute("unique_rowid","some","new value");


To access cell attributes:
    grid.cells(i,j).getAttribute("some");
    grid.cells(i,j).setAttribute("some","new value");

If you want to include such custom attributes in the serialization, some special steps are required:
        grid.xml.row_attrs.push("some");    // will include some attribute of a row in the serialization
        grid.xml.cell_attrs.push("some");    // will include some attribute of a cell in the serialization
This data is not available during dataprocessor calls.